package Server.UI.Test;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import org.hibernate.tutorial.util.HibernateUtil;

import Server.Entity.IceClasses.EMoneyI;

public class Main {
	public static void main(String args[]){
		
		
		System.out.print("\n prova1 \n");
		
		Session session = HibernateUtil.getSessionFactory().openSession();
		
		System.out.print("\n prova2 \n");
		
		session.beginTransaction();		
		
		System.out.print("\n prova3 \n");
		
		//NotificaTaskAssegnato note = new NotificaTaskAssegnato(null);
		EMoneyI soldi = new EMoneyI();
		soldi.setPrezzo(20000);

		try {
			session.save(soldi);
			session.getTransaction().commit();
		} catch (HibernateException e) {
			session.getTransaction().rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		
	}
	/*
	public Long saveCourse(String courseName){
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		Long courseId = null;
		try {
			courseId = (Long) session.save(new Course(courseName));
			session.getTransaction().commit();
		} catch (HibernateException e) {
			session.getTransaction().rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		return courseId;
	}
	
	public void listCourse(){
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		try {
			List courses = session.createQuery("from Course").list();
			for (Iterator iterator = courses.iterator(); iterator.hasNext();)
			{
				Course course = (Course) iterator.next();
				System.out.println(course.getCourseName());
			}
			session.getTransaction().commit();
		} catch (HibernateException e) {
			session.getTransaction().rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
	}
	
	public void updateCourse(Long courseId, String courseName){
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		try {
			Course course = (Course) session.get(Course.class, courseId);
			course.setCourseName(courseName);
			session.getTransaction().commit();
		} catch (HibernateException e) {
		session.getTransaction().rollback();
		e.printStackTrace();
		} finally {
			session.close();
		}
	}
	
	public void deleteCourse(Long courseId){
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		try {
			Course course = (Course) session.get(Course.class, courseId);
			session.delete(course);
			session.getTransaction().commit();
		} catch (HibernateException e) {
		session.getTransaction().rollback();
		e.printStackTrace();
		} finally {
			session.close();
		}
	}*/
}

